/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.neolokura.travian.helper.bo.page;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import java.util.List;

/**
 *
 * @author gustavo
 */
public class SendTroopsPageObject extends PageObject {

    HtmlTextInput t1;
    HtmlTextInput t2;
    HtmlTextInput t3;
    HtmlTextInput t4;
    HtmlTextInput t5;
    HtmlTextInput t6;
    HtmlTextInput t7;
    HtmlTextInput t8;
    HtmlTextInput t9;
    HtmlTextInput t10;
    HtmlTextInput x;
    HtmlTextInput y;
    HtmlForm form;
    HtmlRadioButtonInput reinforcement;
    HtmlRadioButtonInput raid;
    HtmlRadioButtonInput normal;

    public SendTroopsPageObject(HtmlPage page) {
        super(page);

        try {
            form = page.getFormByName("snd");
        } catch (Exception e) {
            for (HtmlForm htmlForm : page.getForms()) {
                form = htmlForm;
            }
        }
        super.setSubmitButton(form.getButtonByName("s1"));
    }

    public void setAttackType(String attackType) throws Exception{

        if(attackType == null || (!attackType.equals("reinforcement") && !attackType.equals("raid") && !attackType.equals("normal"))){
            throw new Exception("No valid attack type");
        }
        List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName("c");

        for (HtmlRadioButtonInput radio : radioButtons) {
            radio.setChecked(false);
            if (attackType.equals("reinforcement") && Integer.parseInt(radio.getValueAttribute()) == 2) {
                radio.setChecked(true);
            }
            if (attackType.equals("normal") && Integer.parseInt(radio.getValueAttribute()) == 3) {
                radio.setChecked(true);
            }
            if (attackType.equals("raid") && Integer.parseInt(radio.getValueAttribute()) == 4) {
                radio.setChecked(true);
            }
        }

    }

    public HtmlTextInput getT1() {
        return t1;
    }

    public void setT1(Integer qty) {
        if (qty != null) {
            this.t1 = form.getInputByName("t1");
            t1.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT10() {
        return t10;
    }

    public void setT10(Integer qty) {
        if (qty != null) {
            this.t10 = form.getInputByName("t10");
            t10.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT2() {
        return t2;
    }

    public void setT2(Integer qty) {
        if (qty != null) {
            this.t2 = form.getInputByName("t2");
            t2.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT3() {
        return t3;
    }

    public void setT3(Integer qty) {
        if (qty != null) {
            this.t3 = form.getInputByName("t3");
            t3.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT4() {
        return t4;
    }

    public void setT4(Integer qty) {
        if (qty != null) {
            this.t4 = form.getInputByName("t4");
            t4.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT5() {
        return t5;
    }

    public void setT5(Integer qty) {
        if (qty != null) {
            this.t5 = form.getInputByName("t5");
            t5.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT6() {
        return t6;
    }

    public void setT6(Integer qty) {
        if (qty != null) {
            this.t6 = form.getInputByName("t6");
            t6.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT7() {
        return t7;
    }

    public void setT7(Integer qty) {
        if (qty != null) {
            this.t7 = form.getInputByName("t7");
            t7.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT8() {
        return t8;
    }

    public void setT8(Integer qty) {
        if (qty != null) {
            this.t8 = form.getInputByName("t8");
            t8.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getT9() {
        return t9;
    }

    public void setT9(Integer qty) {
        if (qty != null) {
            this.t9 = form.getInputByName("t9");
            t9.setValueAttribute(qty.toString());
        }
    }

    public HtmlTextInput getX() {
        return x;
    }

    public void setX(Integer x) {
        if (x != null) {
            this.x = form.getInputByName("x");
            this.x.setValueAttribute(x.toString());
        }
    }

    public HtmlTextInput getY() {
        return y;
    }

    public void setY(Integer y) {
        if (y != null) {
            this.y = form.getInputByName("y");
            this.y.setValueAttribute(y.toString());
        }
    }
}
